package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.deeplearn.domain.DeepMarkProject;
import com.ruoyi.deeplearn.service.IDeepDatasetGroupService;
import com.ruoyi.deeplearn.service.IDeepMarkProjectService;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepMarkTask;
import com.ruoyi.deeplearn.service.IDeepMarkTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标注项目任务Controller
 *
 * @author rww
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/deeplearn/mark/task")
public class DeepMarkTaskController extends BaseController
{
    @Autowired
    private IDeepMarkTaskService deepMarkTaskService;
    @Autowired
    private IDeepMarkProjectService deepMarkProjectService;
    @Autowired
    private IDeepDatasetGroupService deepDatasetGroupService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询标注项目任务列表
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepMarkTask deepMarkTask)
    {
        startPage();
        List<DeepMarkTask> list = deepMarkTaskService.selectDeepMarkTaskList(deepMarkTask);
        return getDataTable(list);
    }
    @GetMapping("/list/all")
    public AjaxResult listAll(DeepMarkTask deepMarkTask)
    {
        List<DeepMarkTask> list = deepMarkTaskService.selectDeepMarkTaskList(deepMarkTask);
        return AjaxResult.success(list);
    }
    /**
     * 导出标注项目任务列表
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:export')")
    @Log(title = "标注项目任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepMarkTask deepMarkTask)
    {
        List<DeepMarkTask> list = deepMarkTaskService.selectDeepMarkTaskList(deepMarkTask);
        ExcelUtil<DeepMarkTask> util = new ExcelUtil<DeepMarkTask>(DeepMarkTask.class);
        util.exportExcel(response, list, "标注项目任务数据");
    }

    /**
     * 获取标注项目任务详细信息
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepMarkTaskService.selectDeepMarkTaskById(id));
    }

    /**
     * 新增标注项目任务
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:add')")
    @Log(title = "标注项目任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepMarkTask deepMarkTask)
    {
        if(deepMarkTask.getMarkProjectId()==null){
            return  AjaxResult.error("项目参数错误");
        }
        DeepMarkProject deepMarkProject = deepMarkProjectService.selectDeepMarkProjectById(deepMarkTask.getMarkProjectId());
        if(deepMarkProject==null){
            return  AjaxResult.error("项目不存在");
        }
        deepMarkTask.setClipSize(deepMarkProject.getClipSize());
        deepMarkTask.setModuleId(deepMarkProject.getModuleId());
        deepMarkTask.setTagGroupId(deepMarkProject.getTagGroupId());
        deepMarkTask.setStatus(DeepMarkTask.STATUS_CREATE);
        int result = deepMarkTaskService.insertDeepMarkTask(deepMarkTask);
        //
        //deepDatasetGroupService.createDatasetGroup();
        //切片---由前端调用
        return toAjax(result);
    }

    /**
     * 修改标注项目任务
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:edit')")
    @Log(title = "标注项目任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepMarkTask deepMarkTask)
    {
        return toAjax(deepMarkTaskService.updateDeepMarkTask(deepMarkTask));
    }

    /**
     * 删除标注项目任务
     */
//    @PreAuthorize("@ss.hasPermi('mark:task:remove')")
    @Log(title = "标注项目任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepMarkTaskService.deleteDeepMarkTaskByIds(ids));
    }
}
